﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_General_SideMenus_MasterSideMenu : System.Web.UI.UserControl
{
    public int MasterAccountID 
    {
        get
        {
            return Convert.ToInt32(Request["ID"]);
        }
    
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        DisplayLogin();
		if(!IsPostBack)
			hlEdit.NavigateUrl = AppParams.URLs.MasterAccount_Edit(MasterAccountID);
    }

    protected void btnCreatAccount_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(tbName.Text))
            return;

        var account = new BO.Account
        {
            Name = tbName.Text,
            MasterAccountID = MasterAccountID,
            EntityStatus = BLL.EntityStatuses.Active
        };
        account.Insert();

        Response.Redirect(AppParams.URLs.ConnectPageUrl(account.ID));
    }

    private void DisplayLogin()
    {
        if (BLL.Authentication.IsCurrentUserAuthenticated())
        {
            lblLogin.Visible = false;
            lblLogout.Visible = true;
        }
        else
        {
            lblLogin.Visible = true;
            lblLogout.Visible = false;
        }

    }

    protected void lbtnLogout_Click(object sender, EventArgs e)
    {
        BLL.Authentication.Logout();
        Response.Redirect("/default.aspx");
    }

}